<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('课文朗读列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>用户ID：</p>
                                <input type="text" name="kkuid" th:value="${kkuid}"/>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <audio controls="controls" id="audio" autoplay="false">
                    <source src=""/>
                </audio>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('yuwen:yuwenaudio:edit')}]];
        var removeFlag = [[${@permission.hasPermi('yuwen:yuwenaudio:remove')}]];
        var vstatusDatas = [[${@dict.getType('kewen_audio_status')}]];
        var prefix = ctx + "yuwen/yuwenaudio";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "课文朗读",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'vid', 
                    title : '录音ID',
                    visible: true
                },
                {
                    field : 'kkuid', 
                    title : '用户ID',
                    visible: true
                },
                {
                    field : 'vstatus', 
                    title : '状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(vstatusDatas, value);
                    }
                },
                {
                    field : 'url', 
                    title : '试听',
                    formatter: function(value, row, index) {
                       return '<a href="javascript:play(\'' + value + '\')" >试听</a>';
                    }
                },
                {
                    field : 'vid',
                    title : '打开分享页',
                    formatter: function(value, row, index) {
                       return '<a href="javascript:openShare(\'' + value + '\', ' + row.vstatus + ')" >分享页</a>';
                    }
                },
                {
                    field : 'kewenid', 
                    title : '课文ID'
                },
                {
                    field : 'vname', 
                    title : '文件名'
                },
                {
                    field : 'uploadTime',
                    title : '上传时间'
                },
                {
                    field : 'reviewTime',
                    title : '审核时间'
                },
                {
                    field : 'sizeFormat',
                    title : '文件大小'
                },
                {
                    field : 'checker', 
                    title : '审核者'
                },
                {
                    field : 'praise', 
                    title : '点赞数'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function play(url){
           var audio = document.getElementById('audio');
           audio.src = url;
           audio.play()
        }

        function openShare(vid, status){
          var btn = []
          btn = ['关闭']
          btn1Callback = function(index){
            layer.close(index)
          }

		   let url = prefix + `/share/${vid}`
           var width = 800;
           var height = ($(window).height() - 50);
           var index = layer.open({
                type: 2,
                area: [width + 'px', height + 'px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: '音频分享页',
                content: url,
                btn: btn,
                // 弹层外区域关闭
                shadeClose: true,
                yes: btn1Callback
            });
            layer.full(index);
		}

    </script>
</body>
</html>